package com.miku.project.service.impl;
import java.util.List;

import cn.hutool.json.JSONUtil;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result.SceneInfo;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result.Amount;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result.PromotionDetail;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result.Payer;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result;
import com.miku.mikuapicommon.model.entity.PaymentInfo;
import com.miku.project.mapper.PaymentInfoMapper;
import com.miku.project.model.vo.PaymentInfoVo;
import com.miku.project.service.PaymentInfoService;
import org.springframework.stereotype.Service;

/**
* @author ThinkBook
* @description 针对表【payment_info(付款信息)】的数据库操作Service实现
* @createDate 2024-06-20 18:55:15
*/
@Service
public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, PaymentInfo>
    implements PaymentInfoService {

    /**
     * 创建付款信息
     * @param paymentInfoVo
     * @return
     */
    @Override
    public boolean createPaymentInfo(PaymentInfoVo paymentInfoVo) {
     String appid = paymentInfoVo.getAppid();
     String mchid = paymentInfoVo.getMchid();
     String outTradeNo = paymentInfoVo.getOutTradeNo();
     String transactionId = paymentInfoVo.getTransactionId();
     String tradeType = paymentInfoVo.getTradeType();
     String tradeState = paymentInfoVo.getTradeState();
     String tradeStateDesc = paymentInfoVo.getTradeStateDesc();
     String bankType = paymentInfoVo.getBankType();
     String attach = paymentInfoVo.getAttach();
     String successTime = paymentInfoVo.getSuccessTime();
     Payer payer = paymentInfoVo.getPayer();
     Amount amount = paymentInfoVo.getAmount();
     SceneInfo sceneInfo = paymentInfoVo.getSceneInfo();
     List<PromotionDetail> promotionDetails = paymentInfoVo.getPromotionDetails();
        PaymentInfo paymentInfo = new PaymentInfo();
        paymentInfo.setOrderNo(paymentInfoVo.getOutTradeNo());
        paymentInfo.setTransactionId(transactionId);
        paymentInfo.setTradeType(tradeType);
        paymentInfo.setTradeState(tradeState);
        if (StringUtils.isNotBlank(successTime)){
            paymentInfo.setSuccessTime(successTime);
        }
        paymentInfo.setOpenid(payer.getOpenid());
        paymentInfo.setPayerTotal(Long.valueOf(amount.getPayerTotal()));
        paymentInfo.setCurrency(amount.getCurrency());
        paymentInfo.setPayerCurrency(amount.getPayerCurrency());
        paymentInfo.setTotal(Long.valueOf(amount.getTotal()));
        paymentInfo.setTradeStateDesc(tradeStateDesc);
        paymentInfo.setContent(JSONUtil.toJsonStr(paymentInfoVo));
        return this.save(paymentInfo);
    }
}




